| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 5 | Cart: new function () { |
||
| 6 | this.addItem = function (itemOfferPriceId, count) { |
||
| 7 | inji.Server.request({ |
||
| 8 | url: 'ecommerce/cart/add', |
||
| 9 | data: { |
||
| 10 | itemOfferPriceId: itemOfferPriceId, |
||
| 11 | count: count, |
||
| 12 | }, |
||
| 13 | success: function (data) { |
||
| 14 | console.log(data); |
||
|
|
|||
| 15 | inji.Server.request({ |
||
| 16 | url: 'ecommerce/cart/getCart', |
||
| 17 | success: function (data) { |
||
| 18 | $("#cart,.cartplace").html(data); |
||
| 19 | } |
||
| 20 | }); |
||
| 21 | } |
||
| 22 | }); |
||
| 23 | } |
||
| 24 | this.calcSum = function () { |
||
| 25 | var form = $('.ecommerce .cart-order_page form'); |
||
| 26 | var formData = new FormData(form[0]); |
||
| 27 | $('.ecommerce .cart-order_page').prepend($('<div style = "position:absolute;width:' + $('.ecommerce .cart-order_page').width() + 'px;height:' + $('.ecommerce .cart-order_page').height() + 'px;background-color: rgba(255, 255, 255, 0.4);z-index:1000000"></div>')); |
||
| 28 | inji.Server.request({ |
||
| 29 | url: form.attr('action'), |
||
| 30 | type: 'POST', |
||
| 31 | data: formData, |
||
| 32 | dataType: 'html', |
||
| 33 | processData: false, |
||
| 34 | success: function (data) { |
||
| 35 | $('.ecommerce .cart-order_page').html($(data).find('.ecommerce .cart-order_page').html()); |
||
| 36 | } |
||
| 37 | }); |
||
| 38 | } |
||
| 39 | this.delItem = function (cart_item_id) { |
||
| 40 | var form = $('.ecommerce .cart-order_page form'); |
||
| 41 | $('.cart_item_id' + cart_item_id).remove(); |
||
| 42 | var formData = new FormData(form[0]); |
||
| 43 | $('.ecommerce .cart-order_page').prepend($('<div style = "position:absolute;width:' + $('.ecommerce .cart-order_page').width() + 'px;height:' + $('.ecommerce .cart-order_page').height() + 'px;background-color: rgba(255, 255, 255, 0.4);z-index:1000000"></div>')); |
||
| 44 | inji.Server.request({ |
||
| 45 | url: form.attr('action'), |
||
| 46 | type: 'POST', |
||
| 47 | data: formData, |
||
| 48 | dataType: 'html', |
||
| 49 | processData: false, |
||
| 50 | success: function (data) { |
||
| 51 | $('.ecommerce .cart-order_page').html($(data).find('.ecommerce .cart-order_page').html()); |
||
| 52 | } |
||
| 53 | }); |
||
| 54 | } |
||
| 55 | this.delItemWidget = function (cart_item_id, callback) { |
||
| 56 | inji.Server.request({ |
||
| 57 | url: '/ecommerce/cart/deleteItem?cartItemId=' + cart_item_id, |
||
| 58 | success: function (data) { |
||
| 59 | $("#cart,.cartplace").html(data); |
||
| 60 | if (callback !== undefined) { |
||
| 61 | callback(); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | }); |
||
| 65 | } |
||
| 66 | }, |
||
| 67 | toggleFav: function (itemId, btn) { |
||
| 157 |